package aw;
import java.rmi.*;
import java.rmi.registry.LocateRegistry;
import java.util.ArrayList;
import java.util.Map;

import utils.ReadMap;

public class GameServer {
	static Map<Integer,ArrayList<String>> map;
	
	public static void main(String args[]){
		
		// Estado inicial de preparacao de jogo
		Static_Variables.stage = Static_Variables.Stage.PREPARE;
		
		// Prepara o jogo
		prepareGame();
		
		Static_Variables.PosIni.add("0*0");
		Static_Variables.PosIni.add("5*5");
		Static_Variables.PosIni.add("1*3");
		Static_Variables.PosIni.add("1*4");
		Static_Variables.PosIni.add("1*5");
		Static_Variables.PosIni.add("1*6");
		
		//Regista o jogo no RMI
		System.setSecurityManager(new RMISecurityManager());
        System.out.println("RMISecurityManager OK");
        try{
        	LocateRegistry.createRegistry(1099);
            ServerInterface server = new AlienWorldImpl();
            System.out.println("Created Interface");
			Naming.rebind("AlienWorld", server); 
            System.out.println("AlienWorld server ready");
        }catch(Exception e) {
            System.out.println("AlienWorld server main " + e.getMessage());
        }
		
        // Provavelmente o ciclo n estara aqui
		// Ciclo de jogo
		/*
		 *  for all agents do
				update()
			end for
			while � gameover do
				for all agents do
					agent.play()
					update()
				end for
			end while
		 */
        
        AlienWorldImpl.idGameReadytoStart();
    }
	
	public static void prepareGame() {
		/*
		Static_Variables.map = ReadMap.ReadMap("map.txt");
		
		// Printa o mapa para a consola
		for (int j = 0; j < Static_Variables.map.size(); j++) {
			ArrayList<String> line = Static_Variables.map.get(j);
			String line_string = "Linha: ";
			for (String string : line) {
				line_string = line_string + " " + string;
			}
			System.out.println(line_string);
		}*/
		
	}
}
